<extend name="./Application/Admin/View/common/base.html" />
<block name="crumb">
    <span class="c-gray en">&gt;</span> 代理中心
    <span class="c-gray en">&gt;</span> 客户资源
</block>
<block name="content">
    <div class="tabBar cl m-b-10">
        <span class="current"><a href="{:U('Customer/index')}">客户列表</a></span>
    </div>

    <form class="form form-horizontal col-xs-6" id="add_custom" method="post" action="{:U('Customer/add_custom')}">
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>客户名称：</label>
            <div class="formControls col-xs-7 col-sm-7">
                <input type="text" class="input-text" id="c_name" name="c_name"/>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>客户手机：</label>
            <div class="formControls col-xs-7 col-sm-7">
                <input type="text" class="input-text" id="mobile" name="mobile" maxlength="11" data-type="number"/>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>客户微信：</label>
            <div class="formControls col-xs-7 col-sm-7">
                <input type="text" class="input-text" id="wx" name="wx_num"/>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">客户地址：</label>
            <div class="formControls col-xs-7 col-sm-7">
                <input type="text" class="input-text" id="c_area" name="c_area"/>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">关键词：</label>
            <div class="formControls col-xs-7 col-sm-7">
                <input type="text" class="input-text" id="keyword" name="keyword"/>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">备注：</label>
            <div class="formControls col-xs-7 col-sm-7">
                <input type="text" class="input-text" id="remark" name="remark"/>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">分配给：</label>
            <div class="formControls col-xs-3 col-sm-3">
                <input type="text" class="input-text" id="search_to"/>
            </div>
            <div class="formControls col-xs-4 col-sm-4">
                <select name="wechat_manager" id="to" class="input-text">
                    <option value="">-- 请选择 --</option>
                </select>
            </div>
        </div>
        <input type="hidden" name="tp" value="" id="tp"/>
        <div class="row cl" style="text-align: center;">
            <label class="form-label col-xs-12 col-sm-12"></label>
            <button id="save" class="btn btn-primary" type="button">添加客户</button>
            <button id="save_stay" class="btn btn-primary" type="button">加了再加</button>
        </div>
    </form>
</block>

<block name="js">
<script type="text/javascript">
    $(function(){
        //添加分类
        $('#save').click(function () {
            var c_name = $('#c_name').val();
            var mobile = $('#mobile').val();
            var wx = $("#wx").val();
            var to = $("#to").val();
            if (c_name == '') {
                layer.alert('客户名称必填！');
                return false;
            }
            if (mobile == '' && wx == '') {
                layer.alert('客户手机与微信至少填一个!');
                return false;
            }
            if (!to) {
                layer.alert('分配人必填!');
                return false;
            }
            $("#add_custom").submit();
        });

        //添加分类
        $('#save_stay').click(function () {
            var c_name = $('#c_name').val();
            var mobile = $('#mobile').val();
            $('#tp').val("stay");
            var wx = $("#wx").val();
            var to = $("#to").val();
            if (c_name == '') {
                layer.alert('客户名称必填！');
                return false;
            }
            if (mobile == '' && wx == '') {
                layer.alert('客户手机与微信至少填一个!');
                return false;
            }
            if (!to) {
                layer.alert('分配人必填!');
                return false;
            }
            $("#add_custom").submit();
        });

        $("#search_to").keyup(function(){
            $aName = $(this).val();
            if($aName != ''){
                getWechatName();
            }else{
                return false;
            }
        });

        $("#search_to").change(function(){
            $aName = $(this).val();
            if($aName != ''){
                getWechatName();
            }else{
                return false;
            }
        });

        function getWechatName()
        {
            $.ajax({
                url: "{:U('Customer/searchManager')}",
                type: "post",
                data: {aName : $aName},
                success: function (data) {
                    if (data) {
                        options = "";
                        $.each(data, function(k, v){
                            options += '<option value="'+ v.id +'">'+ v.name +'</option>';
                        });
                        $("#to").html(options);
                    }
                }
            });
        }
    });
</script>
</block>